The life sentences were handed down to former army officer Saleh Ould Hanenna, the coup ringleader, and three others accused of high treason, lawyers said.
A total of 195 people, most from the military, were on trial in the vast coup-prone former French colony which is hoping to get rich from offshore oil.
A state prosecutor had requested the death penalty for Hanenna and 16 other accused, all believed to be members of a group of renegade soldiers calling itself "Knights of Change".
Hanenna pleaded guilty to a June 2003 attempted putsch, during which he came close to toppling Taya during two days of fierce street fighting in the capital Nouakchott before loyalists regained control.
Mauritania's government says it has since foiled two more coup attempts in 2004 by dissidents linked to Hanenna, who was arrested last October.
"We had two challenges - to avoid the death penalty and reduce the number of those condemned," said defence lawyer Brahim Ould Ebetty.
"We succeeded on both because the acquittal of the three members of the opposition is a delicate political situation for the authorities," he added. He did not immediately say if there would be any appeals.
The rest of the defendants received sentences ranging from one to 15 years in jail. The trial was held in the desert town of Ouad Naga, 50 km (30 miles) east of the capital.
Critics say the two latest coup bids - for which the government has also blamed Burkina Faso and Libya - were a pretext to justify a clampdown on political opponents.
Taya, who first seized power in a coup in 1984, has angered many Arabs in a nation straddling black and Arab Africa by shifting support over the past decade from former Iraqi leader Saddam Hussein to Israel and the United States.